package org.ucas.kgraph.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.ucas.kgraph.dao.FileDao;
import org.ucas.kgraph.entity.File;
import org.ucas.kgraph.utils.exception.NotFoundException;

import java.util.*;

@Transactional
@Service
public class FileService {

  @Autowired
  private FileDao fileDao;

  
  public  List<File> getFileListByUser(Long parent_id,Long account_id, String type, String state) {	
	  return fileDao.findFileListByUser(parent_id,account_id,type,state);
  }

  public  List<File> getFileListAll(Long account_id, String type, String state) {	
	  return fileDao.findFileListAllByUser(account_id,type,state);
  }
  public List getFileListByParent(Long file_id, String type, String state) {
	  return fileDao.findFileListByParent(file_id,type,state);
  } 
  public File load(Long file) {
	if(Long.valueOf(file).equals(Long.valueOf(0))){
		return null;
	}else{
		return fileDao.getOne(file);
	}
  }


  public void create(File tmp) {
	// TODO Auto-generated method stub
	fileDao.save(tmp);
  }
  public List<File> getFileListAll(String type, String state) {
	  return fileDao.findFileListAll(type,state);
  }

  public void delete(Long id) {
	// TODO Auto-generated method stub
	 fileDao.delete(id);
  }
 
  public File rename(Long id, String newname) {
	// TODO Auto-generated method stub
	File file = fileDao.findOne(id);
	file.setName(newname);
	fileDao.save(file);
	return file;
  }

  public List<File> getFileListByAllParent(Long id) {
	// TODO Auto-generated method stub
	  return fileDao.findFileListAllByParent(id);
  }
 
  public List getFileListBySearch(Long file_id,String type, String state, String searchString) {
	  return fileDao.findFileListBySearch(file_id,type,state,searchString);
  }
 
}
